<?php

class admin_Model  extends CI_Model  {
	function __construct()
    {
        parent::__construct();
    }

    public function checkExistEmail($email) {
        $this->db->where('email',$email);
        $this->db->from('users');
        return $this->db->count_all_results()>0;        
    }

    public function checkLogin($email,$password) {
        $this->load->library('session');                
        $this->db->where('email',$email);
        $this->db->where('password',$password);
        $result=$this->db->get('users');                  
        if($result->num_rows() > 0){
            //create session            
            $result=$result->row_array();
            $this->session->set_userdata(array('email'=>$email,'groupId'=>$result['groupId'],'userId'=>$result['id']));
            $this->session->set_userdata('userdata',$result);
            return TRUE;
        }
        return FALSE;
    }

    public function getUser($key) {
        $this->db->where('id',$key);
        $result=$this->db->get('users'); 
        return $result->row_array();
    }

    public function changePass($email, $password) {
        $this->db->where('email',$email);
        $attr = array('password' => $password);
        $ret = $this->db->update('users', $attr);
        return $ret;
    }

    public function getCategoryParent() {
        $this->db->where('parentId',0);
        $result=$this->db->get('pro_categories'); 
        return $result->result();
    }
}
?>